<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Promise</title>
</head>
<body>
    
</body>
<script>
    //189000950 顾啟思
    function Promise(executor){
        let _this = this;3
        _this.$$status = 'pending';
        _this.failCallBack = undefined;
        _this.successCallback = undefined;
        _this.error = undefined;
        executor(resolve.bind(this), reject.bind(this));

        function resolve() {
            if(_this.$$status === 'pending'){
                _this.$$status = 'full'
                _this.successCallback('测试成功！')
            }
        }
        function reject() {
            if(_this.$$status === 'pending'){
                _this.$$status = 'fail'
                _this.failCallBack('出现错误啦！')
            }
        }
    }
    Promise.prototype.then = function(full, fail) {
        this.successCallback = full
        this.failCallBack = fail
    }
    new Promise(function(res,rej){
        setTimeout(()=>res('成功'), 0);
    }).then(result => console.log(result));
</script>
</html>